package com.company.ndklearnproject;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

import androidx.appcompat.app.AppCompatActivity;

import com.company.ndklearnproject.utils.VoiceChangeUtils;

import org.fmod.FMOD;

import java.io.File;

public class VoiceActivity extends AppCompatActivity implements View.OnClickListener {

    private static final String TAG = "VoiceActivity_JNI_Voice";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_voice);
        FMOD.init(this);
        findViewById(R.id.play_voice_normal).setOnClickListener(this);
        findViewById(R.id.play_voice_luoli).setOnClickListener(this);
        findViewById(R.id.play_voice_xiaohuangren).setOnClickListener(this);
        findViewById(R.id.stop_play_voice).setOnClickListener(this);

    }

    private void playVoice(int mode) {
//        File file = new File(getCacheDir(), "Fade.MP3");
//        Log.i(TAG, "onCreate changeLuoliVoice file = " + file.getAbsolutePath());

        new Thread(new Runnable() {
            @Override
            public void run() {
                String path = "file:///android_asset/test.flac";
                VoiceChangeUtils.changeLuoliVoice(mode, path);
                Log.i(TAG, "onCreate changeLuoliVoice");
            }
        }).start();

    }

    @Override
    protected void onDestroy() {
        FMOD.close();
        super.onDestroy();
    }

    @SuppressLint("NonConstantResourceId")
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.play_voice_luoli:
                playVoice(VoiceChangeUtils.MODE_LUOLI);
                break;
            case R.id.play_voice_xiaohuangren:
                playVoice(VoiceChangeUtils.MODE_GAOGUAI);
                break;
            case R.id.stop_play_voice:
                VoiceChangeUtils.stopPlayVoice();
                break;
            case R.id.play_voice_normal:
            default:
                playVoice(VoiceChangeUtils.MODE_NORMAL);
                break;
        }



    }
}